package tina.classparsing;

// make no assumptions about the validity of the object
// consider it as a "data repository"

public class TinaAttribute {
    public enum AttributeType {
        SourceFile,
        ConstantValue,
        Code,
        Exceptions,
        InnerClasses,
        Synthetic,
        LineNumberTable,
        LocalVariableTable,
        Deprecated,
        StackMap,
        SourceDebugExtension,
        EnclosingMethod,
        Signature,
        LocalVariableTypeTable,
        UNKNOWN;
    }
    private AttributeType type;
    public byte[] info;   // used only in case of an unknown attribute
    public long length, code_length; 
    public int constantvalue_index,
               max_stack, max_locals, exception_table_length, attributes_count,
               number_of_exceptions,
               number_of_classes,
               sourcefile_index,
               line_number_table_length,
               local_variable_table_length,
               class_index, method_index,   // used by EnclosingMethod
               signature_index;             // used by Signature
    public int[][] local_variable_table,
                   line_number_table,
                   classes,
                   exception_table;
    public int[] exception_index_table;
    public String debug_extension;


    public TinaAttribute() {
        type = AttributeType.UNKNOWN;
    }


    public TinaAttribute(String name) throws IllegalArgumentException {
        try {
            type = AttributeType.valueOf(AttributeType.class, name);
        } catch(IllegalArgumentException e) {
            System.err.println("Unknown attribute : "+name);
            type = AttributeType.UNKNOWN;
        } catch(NullPointerException e) {
            System.err.println("Unknown attribute : "+name);
            type = AttributeType.UNKNOWN;
        }
    }

    public AttributeType getType() {
        return type;
    }

    public void setType(String name) {
        try {
            type = AttributeType.valueOf(AttributeType.class, name);
        } catch(IllegalArgumentException e) {
            System.err.println("Unknown attribute : "+name);
            type = AttributeType.UNKNOWN;
        }
    }
}